 package java8.base64;
 
 import java.util.Base64;
import java.util.UUID;

 /**
 * @author Administrator
 * @date 2018/11/28
 */
public class MyTest {
    
    public static void main(String[] args) {
        try {
            String base64encodeString = Base64.getEncoder().encodeToString("runoob?java8".getBytes("UTF-8"));
            System.out.println(base64encodeString);
            
            byte[] base64decodeBytes = Base64.getDecoder().decode(base64encodeString);
            System.out.println(new String(base64decodeBytes, "UTF-8"));
            
            base64encodeString = Base64.getUrlEncoder().encodeToString("TutorialsPoint?java8".getBytes("utf-8"));
            System.out.println(base64encodeString);
            
            base64decodeBytes = Base64.getUrlDecoder().decode(base64encodeString);
            System.out.println(new String(base64decodeBytes, "UTF-8"));
            
            StringBuilder stringBuilder = new StringBuilder();
            for(int i = 0; i < 20; ++i) {
                stringBuilder.append(UUID.randomUUID().toString());
            }
            byte[] mimeBytes = stringBuilder.toString().getBytes("utf-8");
            String mimeEncodeString = Base64.getMimeEncoder().encodeToString(mimeBytes);
            System.out.println(mimeEncodeString);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
